package com.zy.qudadid.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.zy.lcpassenger.R;
import com.zy.qudadid.model.StrokeInfor;
import com.zy.qudadid.presenter.StrokeAllPresenter;
import com.zy.qudadid.ui.activity.base.SwipeRecycleViewActivity;
import com.zy.qudadid.ui.adapter.StrokeAllAdapter;
import com.zy.qudadid.ui.view.StrokeAllView;
import com.zy.qudadid.utils.ToolsUtil;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by ASUS on 2017/2/17.
 */

public class StrokeAllActivity extends SwipeRecycleViewActivity<StrokeAllPresenter, StrokeAllAdapter, StrokeInfor> implements StrokeAllView {

    @Bind(R.id.txtRunning)
    TextView txtRunning;
    @Bind(R.id.txtFinished)
    TextView txtFinished;

    public int finished = 2;// 1:已完成订单 2:未完成订单
    public int type = 1;// 1:出租车 3:网约车 2：顺风车 6网约车专车列表 5获取顺风车已发布行程、已完成行程各一条
    public String d = "";

    // private ArrayList<Stroke> list = new ArrayList<>();

    @Override
    protected StrokeAllAdapter provideAdapter() {
        //  return new StrokeAllAdapter(getContext());
        return new StrokeAllAdapter(this, presenter);
    }

    @Override
    protected RecyclerView.LayoutManager provideLayoutManager() {
        return new LinearLayoutManager(getContext());
    }

    @Override
    protected CharSequence provideTitle() {
        return "";
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_stroke_all;
    }

    @Override
    public void initListeners() {

    }

    @Override
    public StrokeAllPresenter createPresenter() {
        return new StrokeAllPresenter();
    }

    @Override
    public void onItemClick(View view, int pos, StrokeInfor item) {
        String state = item.state;
        if(state.equals("5")){
            Bundle bundle = new Bundle();
            bundle.putSerializable("dingdan",item);
            startActivity(new Intent(getContext(), ZhifuActivity.class).putExtra("data", bundle));
        }else if(state.equals("3")){
            StrokeInfor stroke = new StrokeInfor();
            stroke.id = item.id;
            stroke.state = item.state;
            Bundle bundle = new Bundle();
            bundle.putSerializable("stroke",stroke);
            startActivity(new Intent(getContext(), IndexFormActivity.class).putExtra("data", bundle));
        }else if(state.equals("1")){
            StrokeInfor stroke = new StrokeInfor();
            stroke.id = item.id;
            stroke.state = item.state;
            Bundle bundle = new Bundle();
            bundle.putSerializable("stroke",stroke);
            startActivity(new Intent(getContext(), IndexFormActivity.class).putExtra("data", bundle));
        }else if(state.equals("0")){
            StrokeInfor stroke = new StrokeInfor();
            stroke.id = item.id;
            stroke.state = item.state;
            Bundle bundle = new Bundle();
            bundle.putSerializable("stroke",stroke);
            startActivity(new Intent(getContext(), IndexFormActivity.class).putExtra("data", bundle));
        }else if(state.equals("4")){
            StrokeInfor stroke = new StrokeInfor();
            stroke.id = item.id;
            stroke.state = item.state;
            Bundle bundle = new Bundle();
            bundle.putSerializable("stroke",stroke);
            startActivity(new Intent(getContext(), IndexFormActivity.class).putExtra("data", bundle));
        }else if(state.equals("6")){
            Intent it = new Intent();
            Bundle bundle = new Bundle();
            bundle.putSerializable("item",item);
            it.putExtras(bundle);
            it.setClass(getContext(), PingJiaSiJiActivity.class);
            startActivity(it);
        }else if(state.equals("2")){
            StrokeInfor stroke = new StrokeInfor();
            stroke.id = item.id;
            stroke.state = item.state;
            Bundle bundle = new Bundle();
            bundle.putSerializable("stroke",stroke);
            startActivity(new Intent(getContext(), IndexFormActivity.class).putExtra("data", bundle));
        }else if(state.equals("7")){
            StrokeInfor stroke = new StrokeInfor();
            stroke.id = item.id;
            stroke.state = item.state;
            Bundle bundle = new Bundle();
            bundle.putSerializable("stroke",stroke);
            startActivity(new Intent(getContext(), IndexFormActivity.class).putExtra("data", bundle));
        }else if(state.equals("8")){
            Bundle bundle = new Bundle();
            bundle.putSerializable("dingdan",item);
            startActivity(new Intent(getContext(), ZhifuActivity.class).putExtra("data", bundle));
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        switch (tag) {
            case "1":
                tvTitle.setText("出租车行程");

//                Map mapTravel = new HashMap();
//                mapTravel.put("user_id", new UserUtil(getContext()).getUserId());
//                mapTravel.put("type", "1");
//                mapTravel.put("car_type", "1");
//                mapTravel.put("finished", "2");
//                mapTravel.put("nowpage", page);
//                mapTravel.put("page_num", count);
//                String jsonTravel = StringUtil.toJson(mapTravel);
//                try {
//                    d = AESCrypt.getInstance().encrypt(jsonTravel);
//                } catch (Exception ex) {
//                }

                presenter.getData(page,count);
                //  presenter.getData(page,count);
                break;
            case "6":
                tvTitle.setText("网约车行程");
                presenter.getData(page,count);
                break;
            case "2":
                tvTitle.setText("顺风车行程");
                presenter.getData(page,count);
                break;
        }
    }
    String tag;
    @Override
    protected void initThings(Bundle savedInstanceState) {
        super.initThings(savedInstanceState);

        tag = getIntentData().getString("tag");
        type = Integer.parseInt(tag);


    }

//    @Override
//    public void success(ArrayList<Stroke> list) {
//
//    }
//
//    @Override
//    public void successUnfinished(ArrayList<Stroke> data) {
//        ToolsUtil.print("----", "查询成功");
//        refresh(false);
//        bd(data);
//    }

    @Override
    public void success(ArrayList<StrokeInfor> list) {

    }

    @Override
    public void successUnfinished(ArrayList<StrokeInfor> data) {
        ToolsUtil.print("----", "查询成功");
        refresh(false);
        bd(data);
    }

    @Override
    public String getfinished() {
        return finished+"";
    }

    @Override
    public String getType() {
        return type+"";
    }

    @Override
    public void error() {
        ToolsUtil.print("----", "查询失败");
    }

    @Override
    public String getData() {
        return d;
    }


    @OnClick({R.id.txtRunning, R.id.txtFinished})
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.txtFinished: // 已完成订单
                finished = 1;
                page = 1;
                txtRunning.setTextColor(getResources().getColor(R.color.black));
                txtFinished.setTextColor(getResources().getColor(R.color.theme_green));

//                Map map = new HashMap();
//                map.put("user_id", new UserUtil(getContext()).getUserId());
//                // map.put("user_id", 158);
//                map.put("type", "1");
//                map.put("car_type", "1");
//                map.put("finished", "1");
//                map.put("nowpage", page);
//                map.put("page_num", count);
//                String json = StringUtil.toJson(map);
//
//                try {
//                    String data1 = AESCrypt.getInstance().encrypt(json);
//                    d = StringUtil.replaceBlank(data1);
//
//                } catch (Exception ex) {
//                }
                presenter.getData(page,count);
                break;
            case R.id.txtRunning:// 未完成订单
                finished = 2;
                page = 1;
                txtRunning.setTextColor(getResources().getColor(R.color.theme_green));
                txtFinished.setTextColor(getResources().getColor(R.color.black));
//
//                Map mapTravel = new HashMap();
//                mapTravel.put("user_id", new UserUtil(getContext()).getUserId());
//                mapTravel.put("type", "1");
//                mapTravel.put("car_type", "1");
//                mapTravel.put("finished", "2");
//                mapTravel.put("nowpage", page);
//                mapTravel.put("page_num", count);
//                String jsonTravel = StringUtil.toJson(mapTravel);
//                try {
//                    d = AESCrypt.getInstance().encrypt(jsonTravel);
//                } catch (Exception ex) {
//                }


                presenter.getData(page,count);
                break;
        }
    }
}
